﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using Yunwei.Domain.Models;

namespace Yunwei.Web.Areas.RRShop.Models
{
    public class CategoryViewModel
    {
        public int Id { get; set; }

        [Required]
        [StringLength(20, MinimumLength = 1, ErrorMessage = "{2}到{1}个字符")]
        [Display(Name = "名称")]
        public string Name { get; set; }

        [Required]
        [StringLength(200, MinimumLength = 5, ErrorMessage = "{2}到{1}个字符")]
        [Display(Name = "照片")]
        public string Avatar { get; set; }

        [Display(Name = "照片")]
        public string Description { get; set; }

        public int Restaurant_Id { get; set; }

        public Category Category
        {
            get
            {
                var category = new Category()
                {
                    Id = this.Id,
                    Name = this.Name,
                    Avatar = this.Avatar,
                    Description = this.Description,
                    Restaurant_Id = this.Restaurant_Id
                };

                return category;
            }
        }

        public static CategoryViewModel FromCategory(Category category)
        {
            CategoryViewModel cvm = new CategoryViewModel()
            {
                Id = category.Id,
                Name = category.Name,
                Avatar = category.Avatar,
                Description = category.Description,
                Restaurant_Id = category.Restaurant_Id
            };
            return cvm;
        }
    }
}